Skip to content

feat(gts): enforce x-gts-closed-derivations in OP#12 chain validation - #111

Open
AndrejK666 wants to merge 1 commit into
GlobalTypeSystem:mainfrom
AndrejK666:feat/x-gts-closed-derivations
Open

feat(gts): enforce x-gts-closed-derivations in OP#12 chain validation#111
AndrejK666 wants to merge 1 commit into
GlobalTypeSystem:mainfrom
AndrejK666:feat/x-gts-closed-derivations

Conversation

@AndrejK666

@AndrejK666 AndrejK666 commented Aug 3, 2026

Copy link
Copy Markdown

Summary

Implements the x-gts-closed-derivations schema modifier proposed in GlobalTypeSystem/gts-spec# (0.14 draft, §9.11.4): a base type may require every derived schema to resolve to a closed content model at its own top level. Enforced in validate_schema_chain (OP#12) next to the existing x-gts-final guard.

Changes
gts/src/schema_modifiers.rs
new constant X_GTS_CLOSED_DERIVATIONS with doc comment;
validate_schema_modifiers: boolean-only value, top-level placement (same fail-fast rule as the other modifiers), and rejection of the meaningless x-gts-final + x-gts-closed-derivations combination.
gts/src/store.rs — in validate_schema_chain, for each (base, derived) pair: if the base declares the modifier, the derived schema's effective top-level additionalProperties (via the existing extract_effective_schema, which already folds allOf through the closedness-preserving lattice) must be false; otherwise StoreError::ValidationError naming the modifier, the base and the derived id.
gts/src/store_test.rs — five tests:
closed derived schema under a closed-derivations base → passes;
derived with additionalProperties: true → rejected (message names the modifier);
derived with additionalProperties omitted (default-open) → rejected;
closedness contributed by an allOf conjunct → passes;
final + closed-derivations on one schema → modifier validation error.
Why only direct derivations are checked

A closed derived level already prevents grandchildren from adding properties (§3.1), and a grandchild re-opening the level would accept instances its closed parent rejects — failing derivation compatibility (§4.1) through the existing checks. See spec §9.11.4 item 3.

Testing
bash
cargo test -p gts

All existing tests pass unchanged (the modifier is opt-in; schemas without it are unaffected).

Related
Spec: GlobalTypeSystem/gts-spec#
Motivating discussion: gears-rust tenant-metadata envelope (open abstract base + mandatory-closed derived metadata schemas); pairs with the planned open-content-model support in struct_to_gts_schema.

Summary by CodeRabbit

  • New Features

    • Added support for marking schemas as requiring closed derived schemas.
    • Derived schemas must explicitly disallow additional properties when this setting is enabled.
    • Added validation for supported placement and boolean configuration.
  • Bug Fixes

    • Prevented incompatible use of closed-derivation and final schema settings.
    • Improved validation errors for invalid or open derived schemas.
  • Tests

    • Added coverage for valid closed schemas, composed schemas, and rejected configurations.

New schema modifier (spec 0.14 draft, S9.11.4): a base type may require
every derived schema to resolve to a closed content model at its own
top level (effective additionalProperties: false). Enforced in
validate_schema_chain next to the x-gts-final guard, using the
existing effective-schema extraction (allOf-closedness lattice).

Modifier validation: boolean-only, top-level placement, rejected in
combination with x-gts-final (a final type has no derivations).

Tests: closed derived passes; open and default-open rejected;
closedness via allOf conjunct passes; final+closed-derivations
rejected.

Signed-off-by: Andrej Kuchma <Andrej.Kuchma@constructor.tech>
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 532b4030-94b0-42d4-ae1d-1f497128c5f8

📥 Commits

Reviewing files that changed from the base of the PR and between c83b308 and 671bf54.

📒 Files selected for processing (3)
  • gts/src/schema_modifiers.rs
  • gts/src/store.rs
  • gts/src/store_test.rs

📝 Walkthrough

Walkthrough

The PR adds x-gts-closed-derivations, validates its schema placement and compatibility, enforces closed derived schemas during chain validation, and adds tests for accepted and rejected derivation patterns.

Changes

Closed derivation validation

Layer / File(s) Summary
Modifier contract and placement validation
gts/src/schema_modifiers.rs
Adds the public modifier constant. Validates boolean type, top-level placement, and incompatibility with x-gts-final.
Schema-chain closedness enforcement
gts/src/store.rs
Rejects derived schemas whose effective top-level content model does not set additionalProperties to false.
Closed derivation test coverage
gts/src/store_test.rs
Tests explicit closedness, explicit openness, omitted additionalProperties, allOf closedness, and conflicting modifiers.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant BaseSchema
  participant validate_schema_chain
  participant DerivedSchema
  BaseSchema->>validate_schema_chain: declare x-gts-closed-derivations
  validate_schema_chain->>DerivedSchema: resolve top-level content model
  DerivedSchema-->>validate_schema_chain: return additionalProperties setting
  validate_schema_chain-->>BaseSchema: accept or return ValidationError
Loading

Possibly related PRs

Suggested reviewers: aviator5, artifizer

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: enforcing x-gts-closed-derivations during OP#12 chain validation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant